// miniprogram/pages/chart/billdetail.js
const db = wx.cloud.database()
const _ = db.command

Page({
  data: {

  },

  bindEditClick: function() {
    if (this.data.type == '支出' || this.data.type == '收入') {
      wx.navigateTo({
        url: 'billedit?id=' + this.data.id + '&openid=' + this.data.openid + '&type=' + this.data.type + '&account=' + this.data.account + '&desc=' + this.data.desc + '&datetime=' + this.data.datetime + '&cate=' + this.data.cate + '&amount=' + this.data.amount
      })
    }
    else {
      wx.navigateTo({
        url: 'billedit?id=' + this.data.id + '&openid=' + this.data.openid + '&type=' + this.data.type + '&account1=' + this.data.account1 + '&account2=' + this.data.account2 + '&desc=' + this.data.desc + '&datetime=' + this.data.datetime + '&amount=' + this.data.amount
      })
    }
  },

  previewImg: function(e) {
    console.log(e.currentTarget.dataset)
  },

  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: '账单详情',
    })

    this.setData({
      id: options.id,
      openid: options.openid,
      type: options.type,
      account: options.account,
      desc: options.desc,
      datetime: options.datetime,
      cate: options.cate,
      amount: options.amount,
      account1: options.account1,
      account2: options.account2
    })
    db.collection('user_bill').where({
      _id: this.data.id
    }).get().then(res => {
      this.setData({
        chooseFiles: res.data[0].imgs
      })
    })
  }
})